
import java.io.IOException;
import java.util.Arrays;

import java.util.StringTokenizer;

public class Main{

	public static void main(String[] args) throws IOException {
		java.io.BufferedReader r = new java.io.BufferedReader(
				new java.io.InputStreamReader(System.in));

		int number = Integer.parseInt(r.readLine());
		int i = 0;
		for (int i1 = 0; i1 < number; i1++) {

			String s = r.readLine();
			StringTokenizer tokenizer = new StringTokenizer(s);

			int m = Integer.parseInt(tokenizer.nextToken());
			int n = Integer.parseInt(tokenizer.nextToken());
		
			if (m == 1)
				m = 2;

			int d = n - m + 1;

			boolean[] a = new boolean[d];

			Arrays.fill(a, true);

			for (i = m % 2; i < d; i += 2)
				a[i] = false;

			for (i = 3; i * i <= n; i += 2) {
				if (i >= m && !a[i - m]) {
					continue;
				}
				int j = m / i * i;
				if (j < m) {
					j += i;
				}
				if (j == i) {
					j += i;
				}
				j -= m;

				for (; j < d; j += i) {
					a[j] = false;
				}
			}

			for (i = m; i <= n; i++) {
				if (i == 1) {
					a[i - m] = false;
				}
				if (i == 2) {
					a[i - m] = true;
				}
				if (a[i - m]) {
					System.out.println(i);
				}
			}

		

		}
	}
}

